package jp.co.apl.haven.inject;

import jp.co.apl.haven.persistence.Persistence;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.inject.AbstractModule;

public abstract class PersistenceModule extends AbstractModule {

    private final Logger log = LoggerFactory.getLogger(PersistenceModule.class);

    protected String url;
    protected String username;
    protected String password;

    public PersistenceModule() {
    }

    public PersistenceModule(String url, String username, String password) {
        super();
        this.url = url;
        this.username = username;
        this.password = password;
    }

    @Override
    protected void configure() {
        log.debug("configure start");

        bind(Persistence.class).to(getPersistenceClass());
        doConfigure();

        log.debug("configure end");
    }

    protected abstract void doConfigure();

    protected abstract Class<? extends Persistence> getPersistenceClass();

    public void setUrl(String url) {
        this.url = url;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public void setPassword(String password) {
        this.password = password;
    }

}
